package com.cwh.taskcenter.event;

import com.cwh.taskcenter.domain.event.DomainEvent;
import com.cwh.taskcenter.domain.event.DomainEventPublisher;
import com.cwh.taskcenter.domain.system.event.SmsSendEvent;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @author cwh
 */
@Slf4j
@Component
public class DomainEventPublisherImpl implements DomainEventPublisher {

    @Resource
    private ApplicationContext applicationContext;

    @Override
    public void publish(DomainEvent event) {
        if (event instanceof SmsSendEvent) {
            handleSmsSendEvent((SmsSendEvent) event);
        }
    }

    private void handleSmsSendEvent(SmsSendEvent event) {
        applicationContext.publishEvent(event);
    }

}
